package com.wpam.scrabble.mobile;
import java.util.HashMap;
import android.bluetooth.BluetoothDevice;
import com.wpam.scrabble.mobile.communication.bt.DeviceNetworkInfo;

public class PlayerManager {
	
	private HashMap<String, String> nameAddress_;
	
	public PlayerManager() {
		nameAddress_ = new HashMap<String, String>();
	}
	
	public void addPlayer(String name, String address) {
		nameAddress_.put(name, address);
	}
	
	public String getAddressByName(String name) {
		return nameAddress_.get(name);
	}
	
	public String getNameByAddress(String address) {
		
		for (String name : nameAddress_.keySet()) {
			if (nameAddress_.get(name).equals(address))
				return name;
		}
		return null;
	}
	
	public String getNameOfSender(BluetoothDevice device) {
		return getNameByAddress(device.getAddress());
	}
	
	public String getNameOfSender(DeviceNetworkInfo device) {
		return getNameByAddress(device.getSock().getRemoteDevice().getAddress());
	}
}
